package com.heima.behavior.controller;

import com.heima.behavior.dto.BehaviorDto;
import com.heima.behavior.service.IApBehaviorEntryService;
import com.heima.behavior.service.impl.ApBehaviorEntryServiceImpl;
import com.heima.common.dto.ResponseResult;
import com.heima.common.dto.User;
import com.heima.common.enums.AppHttpCodeEnum;
import com.heima.common.util.UserThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v1/behavior")
public class BehaviorController {

//    /load_article_behavior/

    @Autowired
    private IApBehaviorEntryService apBehaviorEntryService;

    @PostMapping(value = "/load_article_behavior" ,name = "回显当前登录人对文章的行为")
    public ResponseResult loadArticleBehavior(@RequestBody BehaviorDto dto){
        User user = UserThreadLocalUtil.get();
        if(user==null){
            return ResponseResult.errorResult(AppHttpCodeEnum.NEED_LOGIN);
        }
        dto.setUserId(user.getUserId());
        return apBehaviorEntryService.loadArticleBehavior(dto);
    }
}
